import {getStore, setStore} from "../../util/store.js";

const common = {
  state: {
    currentMenu: getStore({name: 'currentMenu'}) || -1,
    currentNav: getStore({name: 'currentNav'}) || 0,
    topMenu: getStore({name: 'topMenu'}) || -1,
    userInfo: getStore({name: 'userInfo'}) || {},
    refreshFlag: false,
    onSiteList: {},
    wait: true,
    autoStatusData: {}
  },
  mutations: {
    SET_CURRENTMENU: (state, payload) => {
      state.currentMenu = payload;
      setStore({name: 'currentMenu', content: payload})
    },
    SET_CURRENTNAV: (state, payload) => {
      state.currentNav = payload;
      setStore({name: 'currentNav', content: payload})
    },
    SET_TOPMENU: (state, payload) => {
      state.topMenu = payload;
      setStore({name: 'topMenu', content: payload})
    },
    SET_USERINFO: (state, payload) => {
      state.userInfo = payload;
      setStore({name: 'userInfo', content: payload})
    },
    SET_REFRESHFLAG: (state, payload) => {
      state.refreshFlag = payload;
    },
    SET_ONSITELIST: (state, payload) => {
      state.onSiteList = payload;
    },
    SET_WAIT: (state, payload) => {
      state.wait = payload;
    },
    SET_AUTOSTATUSDATA: (state, payload) => {
      state.autoStatusData = payload;
    },
  },
  actions: {
    SET_RESEAT: ({commit, state}) => {
      commit('SET_CURRENTMENU', -1)
      commit('SET_CURRENTNAV', 0)
      commit('SET_TOPMENU', -1)
      commit('SET_USERINFO', {})
    }
  }
}
export default common
